export const ACT = {
  submitReservation: 'sales_lead',
  home: 'home_pv',
  reservation: 'btn1',
  submit: 'btn2',
  page1: 'page1',
  page2: 'page2',
  page3: 'page3',
};

const startDate = (new Date()).getTime();

export default function log(act, more) {
  const user = window.localStorage.getItem('CHUANQI_USER');
  let src = `https://c.wkanx.com/dummy?log=gs3&act=${act}&uid=${user}`;
  if (more) src += more;
  new Image().src = src;
}

export function init() {
  let user = window.localStorage.getItem('CHUANQI_USER');
  if (!user) {
    user = `${(new Date()).getTime()}_${parseInt(Math.random() * 1000, 10)}`;
    window.localStorage.setItem('CHUANQI_USER', user);
  }
  window.onbeforeunload = function ll() {
    const endDate = (new Date()).getTime();
    const stayTime = endDate - startDate;
    log('user_stay', `&time=${stayTime}`);
  };
}
